package com.ruoyi.xsc.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xsc.domain.Cheer;
import com.ruoyi.xsc.service.ICheerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 加油站Controller
 * 
 * @author xsc
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/cheer")
public class CheerController extends BaseController
{
    @Autowired
    private ICheerService cheerService;

// 对外提供的接口
    /**
     * 查询加油站列表
     */
    @InnerAuth
    @GetMapping("/getList")
    public List<Cheer> getList()
    {
        List<Cheer> list = cheerService.selectCheerList(null);
        return list;
    }


    /**
     * 查询加油站列表
     */
    @RequiresPermissions("cheer:cheer:list")
    @GetMapping("/list")
    public TableDataInfo list(Cheer cheer)
    {
        startPage();
        List<Cheer> list = cheerService.selectCheerList(cheer);
        return getDataTable(list);
    }

    /**
     * 导出加油站列表
     */
    @RequiresPermissions("cheer:cheer:export")
    @Log(title = "加油站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cheer cheer)
    {
        List<Cheer> list = cheerService.selectCheerList(cheer);
        ExcelUtil<Cheer> util = new ExcelUtil<Cheer>(Cheer.class);
        util.exportExcel(response, list, "加油站数据");
    }

    /**
     * 获取加油站详细信息
     */
    @RequiresPermissions("cheer:cheer:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cheerService.selectCheerById(id));
    }

    /**
     * 新增加油站
     */
    @RequiresPermissions("cheer:cheer:add")
    @Log(title = "加油站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cheer cheer)
    {
        return toAjax(cheerService.insertCheer(cheer));
    }

    /**
     * 修改加油站
     */
    @RequiresPermissions("cheer:cheer:edit")
    @Log(title = "加油站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cheer cheer)
    {
        return toAjax(cheerService.updateCheer(cheer));
    }

    /**
     * 删除加油站
     */
    @RequiresPermissions("cheer:cheer:remove")
    @Log(title = "加油站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cheerService.deleteCheerByIds(ids));
    }
}
